import axios from 'axios'
import util from '../util'

const httpUrl = 'http://localhost:8080/'

axios.defaults.withCredentials = true

const concatUrl = (apiUrl) => {
  return httpUrl + apiUrl
}

const api = {
  login: ({payload, callback}) => {
    const params = util.createURLSearchParams(payload)

    axios
      .post(concatUrl('sys/login'), params)
      .then(response => {
        if (callback != null && typeof callback === 'function') {
          callback(response)
        }
      })
  },
  getMenuList: ({payload, callback}) => {
    axios
      .post(concatUrl('sys/menu_list'))
      .then(response => {
        if (callback != null && typeof callback === 'function') {
          callback(response)
        }
      })
  },
  queryBillList: ({payload, callback}) => {
    const params = util.createURLSearchParams(payload)

    axios
      .post(concatUrl('/bill/queryBillList'), params)
      .then(response => {
        if (callback != null && typeof callback === 'function') {
          callback(response)
        }
      })
  },
  addBill: ({payload, callback}) => {
    console.log(payload)
    const params = util.createURLSearchParams(payload)

    axios
      .post(concatUrl('/bill/addBill'), params)
      .then(response => {
        if (callback != null && typeof callback === 'function') {
          callback(response)
        }
      })
  },
  queryDDWList: ({payload, callback}) => {
    axios
      .post(concatUrl('/bill/queryDDWList'))
      .then(response => {
        if (callback != null && typeof callback === 'function') {
          callback(response)
        }
      })
  }
}

export default api
